import router from '../../router';
import { reactive } from "vue";

const state = {
	visitedViews: reactive([]),//存储访问过的路由
}

const mutations = {
	ADD_TAGS: (state: any, route: any) => { //缓存访问过的路由
		if (route.meta.breadcrumb) return;
		let obj = {
			path: route.path,
			title: route.meta.title,
			affix: route.meta.affix
		}
		if (!state.visitedViews.some((item: any) => item.path == obj.path)) {
			state.visitedViews.push(obj)
		}
	},
	DEL_TAGS: (state: any, path: any) => {//删除缓存的路由
		state.visitedViews = state.visitedViews.filter((item: any) => item.path !== path)
	}
}

const actions = {
	addTagsView({ commit }: any, route: any) {
		commit('ADD_TAGS', route)
	},
	delTagsView({ commit }: any, path: any) {
		commit('DEL_TAGS', path)
	}
}

export default {
	namespaced: true,
	state,
	mutations,
	actions
}